package com.macro.mall.dto;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Date;
import java.util.List;

/**
 * 小红书订单视图对象
 * Created by AI on 2025/09/15.
 */
@Data
@ApiModel("小红书订单视图对象")
public class XhsOrderVO {
    
    @ApiModelProperty("订单ID")
    private Long id;
    
    @ApiModelProperty("订单号")
    private String outOrderId;
    
    @ApiModelProperty("用户手机号")
    private String phone;
    
    @ApiModelProperty("商品名称")
    private String productName;
    
    @ApiModelProperty("商品ID")
    private Integer productId;
    
    @ApiModelProperty("订单金额(分)")
    private Long finalPrice;
    
    @ApiModelProperty("订单金额(元)")
    private String finalPriceYuan;
    
    @ApiModelProperty("支付方式代码：1->微信；2->支付宝；99->其它")
    private Integer payChannel;
    
    @ApiModelProperty("支付方式文本")
    private String payChannelText;
    
    @ApiModelProperty("订单来源")
    private String sourceType = "小红书小程序";
    
    @ApiModelProperty("原始订单状态：0->待支付；1->支付成功；2->支付失败；3->已取消；4->已退款；5->已完成")
    private Integer orderStatus;
    
    @ApiModelProperty("显示状态文本")
    private String displayStatusText;
    
    @ApiModelProperty("状态标签颜色：primary/success/warning/danger/info")
    private String statusColor;
    
    @ApiModelProperty("是否已过期")
    private Boolean isExpired;
    
    @ApiModelProperty("过期时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date orderExpiredTime;
    
    @ApiModelProperty("创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date createTime;
    
    @ApiModelProperty("支付时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date payTime;
    
    @ApiModelProperty("可执行操作列表")
    private List<String> availableActions;
    
    /**
     * 设置订单金额并自动计算元格式
     */
    public void setFinalPrice(Long finalPrice) {
        this.finalPrice = finalPrice;
        if (finalPrice != null) {
            BigDecimal yuan = new BigDecimal(finalPrice).divide(new BigDecimal(100), 2, RoundingMode.HALF_UP);
            this.finalPriceYuan = yuan.toString();
        }
    }
    
    /**
     * 设置支付方式并自动设置文本描述
     */
    public void setPayChannel(Integer payChannel) {
        this.payChannel = payChannel;
        if (payChannel != null) {
            switch (payChannel) {
                case 1:
                    this.payChannelText = "微信";
                    break;
                case 2:
                    this.payChannelText = "支付宝";
                    break;
                case 99:
                    this.payChannelText = "其它";
                    break;
                default:
                    this.payChannelText = "未知";
                    break;
            }
        }
    }
    
    /**
     * 设置订单状态并自动设置显示文本和颜色
     */
    public void setDisplayStatus(Integer orderStatus, Boolean isExpired) {
        this.orderStatus = orderStatus;
        this.isExpired = isExpired;
        
        if (isExpired != null && isExpired) {
            this.displayStatusText = "已过期";
            this.statusColor = "info";
        } else if (orderStatus != null) {
            switch (orderStatus) {
                case 0:
                    this.displayStatusText = "待支付";
                    this.statusColor = "warning";
                    break;
                case 1:
                    this.displayStatusText = "支付成功";
                    this.statusColor = "primary";
                    break;
                case 2:
                    this.displayStatusText = "支付失败";
                    this.statusColor = "danger";
                    break;
                case 3:
                    this.displayStatusText = "已取消";
                    this.statusColor = "info";
                    break;
                case 4:
                    this.displayStatusText = "已退款";
                    this.statusColor = "danger";
                    break;
                case 5:
                    this.displayStatusText = "已完成";
                    this.statusColor = "success";
                    break;
                default:
                    this.displayStatusText = "未知状态";
                    this.statusColor = "info";
                    break;
            }
        }
    }
}
